package jp.ac.waseda.cs.washi.game.scene;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import jp.ac.waseda.cs.washi.game.GameEnvironment;
import jp.ac.waseda.cs.washi.game.GameManager;
import jp.ac.waseda.cs.washi.game.api.GameInfo;
import jp.ac.waseda.cs.washi.game.api.Player;
import jp.ac.waseda.cs.washi.game.api.PlayerAction;
import jp.ac.waseda.cs.washi.gameaiarena.gui.Renderer;
import jp.ac.waseda.cs.washi.gameaiarena.runner.AbstractRunner;
import jp.ac.waseda.cs.washi.gameaiarena.scene.Scene;

public class ContestScene extends GameScene {

	private final List<AbstractRunner<GameInfo, PlayerAction, Player>> _runners;
	private final int _roundTime;
	private int _mapIndex;

	public ContestScene(AbstractRunner<GameInfo, PlayerAction, Player> player1,
			AbstractRunner<GameInfo, PlayerAction, Player> player2,
			int mapIndex, int roundTime) {
		ArrayList<AbstractRunner<GameInfo, PlayerAction, Player>> runners = new ArrayList<AbstractRunner<GameInfo, PlayerAction, Player>>();
		runners.add(player1);
		runners.add(player2);
		_runners = Collections.unmodifiableList(runners);
		_roundTime = roundTime;
		_mapIndex = mapIndex;
	}

	@Override
	public void initialize(GameEnvironment env) {
		Renderer render = env.getRenderer();
		_gameManager = new GameManager(render, 2, _mapIndex, _roundTime);
		_gameManager.initialize(_runners);
		render.waitLoadImage();
	}

	@Override
	public Scene<GameEnvironment> run(GameEnvironment env) {
		if (!_gameManager.advance(_runners)) {
			return null;
		}
		return this;
	}
}
